import QtQuick 2.0
import QtQuick.Controls 2.1

TextField {
    id: search

    property var searchFun: null

    anchors.top: parent.top
    anchors.right: parent.right
    anchors.left: parent.left
    anchors.margins: 5

    placeholderText: "搜索"

    clip: true
    font.pointSize: 11

    background: Rectangle{
        radius: 16
        border.color: "gray"
        border.width: 2
    }

    Keys.onReturnPressed: {
        if(searchFun) {
            searchFun();
        } else {
            console.error("search callback not initialized.");
        }
    }

    Keys.onEnterPressed: {
        if(searchFun) {
            searchFun();
        } else {
            console.error("search callback not initialized.");
        }
    }

    Image {
        anchors.verticalCenter: parent.verticalCenter
        anchors.right: parent.right
        anchors.rightMargin: 8

        width: 14
        height: 14
        source: "qrc:/images/search.png"

        MouseArea {
            anchors.fill: parent
            onClicked: {
               searchFun();
            }
        }
    }
}
